{include file="common/head"/}
<style>
</style>
<div style="margin: 15px;" class="fadeInUp animated">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>添加用户</legend>
    </fieldset>
    <form class="layui-form layui-form-pane margin">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名：</label>
            <div class="layui-input-2">
                <input type="text" name="username" lay-verify="required" id="username" value="" placeholder="{:lang('pleaseEnter')}用户名" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机：</label>
            <div class="layui-input-2">
                <input type="number" name="tel" id="tel" maxlength="11" value="" lay-verify="required" placeholder="{:lang('pleaseEnter')}手机号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别：</label>
            <div class="layui-input-2">
                <input type="radio" name="sex" value="1" title="男" checked="">
                <input type="radio" name="sex" value="2" title="女">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码：</label>
            <div class="layui-input-2">
                <input type="password" name="password" lay-verify="required" maxlength="20" id="password" value="" placeholder="{:lang('pleaseEnter')}密码" class="layui-input">
            </div>
        </div>
        <!--<div class="layui-form-item">-->
            <!--<label class="layui-form-label">确认密码：</label>-->
            <!--<div class="layui-input-2">-->
                <!--<input type="password" name="repassword" lay-verify="required" id="repassword" value="" placeholder="{:lang('pleaseEnter')}确认密码" class="layui-input">-->
            <!--</div>-->
        <!--</div>-->
        <div class="layui-form-item">
                <button type="button" class="layui-btn " lay-submit="" lay-filter="add">立即提交</button>
                <a href="{:url('User/userList')}" class="layui-btn layui-btn-primary">返回</a>
        </div>
    </form>
</div>
</body>
{include file="common/foot"/}
<script>
    layui.use(['form','jquery', 'layer'], function () {
        var form = layui.form,layer = layui.layer;$= layui.jquery;

        // 监听常规提交
        form.on('submit(add)', function (data) {
            //var loading = layer.load();

            //验证手机号
            var reg = /^1(3|4|5|6|7|8|9)\d{9}$/;
            var reg_1 = /^0[\d]{2,3}-[\d]{7,8}$/;
            if(data.field.tel){
                if (!reg.test(data.field.tel) && !reg_1.test(data.field.tel)) {
                    layer.msg("手机号错误!", {time: 1000, icon: 2});
                    return false;
                }
            }

            if(data.field.password.length < 6 || data.field.password.length>20){
                layer.msg("密码必须是6-20位之间!", {time: 1000, icon: 2});
                return false;
            }
            console.log(data.field);
            return false;
            // 提交到方法 默认为本身
            $.post("{:url('userAdd')}",data.field,function(res){
                layer.close(loading);
                if(res.code == 0){
                    layer.msg(res.msg,{time:1000,icon:1});
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                }
            });
            return false;
        });
    });
</script>
</html>